/*
 * p1085.cpp
 *
 *  Created on: 2013-10-28
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
int edge[][2] =
{
{ 1, 2 },
{ 1, 3 },
{ 2, 3 },
{ 2, 4 },
{ 2, 5 },
{ 4, 5 },
{ 3, 5 },
{ 3, 6 },
{ 5, 6 },
{ 4, 7 },
{ 4, 8 },
{ 7, 8 },
{ 5, 8 },
{ 5, 9 },
{ 8, 9 },
{ 6, 9 },
{ 6, 10 },
{ 9, 10 } };
int tri[][3] =
{
{ 0, 1, 2 },
{ 3, 4, 5 },
{ 2, 4, 6 },
{ 6, 7, 8 },
{ 9, 10, 11 },
{ 5, 10, 12 },
{ 12, 13, 14 },
{ 8, 13, 15 },
{ 15, 16, 17 }, };
int p[19], idx[12], cnt;
bool vis[19];
int dp[1 << 12];
int calc(int state, int e)//当前状态+入一条边e所能获得的得分
{
	int ans = 0, t = 0;
	for (int i = 0; i < 9; i++)
	{
		bool flag = 0;
		for (int j = 0; j < 3; j++)
			if (e == tri[i][j])
			{
				flag = true;
				break;
			}
		if (flag)
		{
			t++;
			for (int j = 0; j < 3; j++)
			{
				if (!(p[tri[i][j]] & state || e == tri[i][j]))
				{
					ans--;
					break;
				}
			}
			ans++;
		}
		if (t == 2)
			break;
	}
	return ans;
}
int dfs(int state, int now, int last)
{
	if (dp[now] != -inf)
		return dp[now];
	int ans = -inf;
	for (int i = 0; i < cnt; i++)
		if (!(p[i] & now))
		{
			int t = calc(state, idx[i]);
			if (t > 0)
			{
				ans
						= max(ans, t + dfs(state | p[idx[i]], now | p[i], last
								- t));
			}
			else
				ans = max(ans, last - dfs(state | p[idx[i]], now | p[i], last));
		}
	return dp[now] = ans;
}
int main()
{
	int T;
	p[0] = 1;
	for (int i = 1; i <= 18; i++)
		p[i] = p[i - 1] * 2;
	scanf("%d", &T);
	int cas = 0;
	while (T--)
	{
		int n;
		scanf("%d", &n);
		int side = 0, m0 = 0, m1 = 0, state = 0;
		memset(vis, 0, sizeof(vis));
		while (n--)
		{
			int u, v;
			scanf("%d%d", &u, &v);
			if (u > v)
				swap(u, v);
			for (int i = 0; i < 18; i++)
				if (u == edge[i][0] && v == edge[i][1])
				{
					vis[i] = true;
					int t = calc(state, i);
					state |= p[i];
					if (side == 0)
						m0 += t;
					else
						m1 += t;
					if(!t)side = 1 - side;
					break;
				}
		}
		cnt = 0;
		for (int i = 0; i < 18; i++)
			if (!vis[i])
				idx[cnt++] = i;
		for (int i = 0; i < (1 << cnt); i++)
			dp[i] = -inf;
		dp[(1 << cnt) - 1] = 0;
		if (side == 0)
		{
			m0 += dfs(state, 0, 9 - m0 - m1);
			m1 = 9 - m0;
		}
		else
		{
			m1 += dfs(state, 0, 9 - m0 - m1);
			m0 = 9 - m1;
		}
		printf("Game %d: %s wins.\n", ++cas, m0 > m1 ? "A" : "B");
	}
	return 0;
}
